import { ecs } from 'db://app-game/libs/ecs/ECS';
import { TableRoleJob } from '../../../../table/TableRoleJob';
import { RoleAttributeEnum, RoleDragonBonesList } from '../Role.type';
import { RoleModelComp } from './RoleModelComp';

/** 职业组件 */
@ecs.register('RoleModelJob')
export class RoleModelJobComp extends ecs.Comp {
  private table: TableRoleJob = new TableRoleJob();
  /** 职业编号编号 */
  private _id: number = -1;
  get id(): number {
    return this._id;
  }
  set id(value: number) {
    this.table.init(value);
    this._id = value;

    let attributes = this.ent.get(RoleModelComp).attributes;

    attributes.get(RoleAttributeEnum.Hp).job = this.hp;
    attributes.get(RoleAttributeEnum.Mp).job = this.mp;
    attributes.get(RoleAttributeEnum.Attack).job = this.attack;
    attributes.get(RoleAttributeEnum.MagicAttack).job = this.magicAttack;
    attributes.get(RoleAttributeEnum.Defense).job = this.defense;
    attributes.get(RoleAttributeEnum.MagicDefense).job = this.magicDefense;
    attributes.get(RoleAttributeEnum.AttackSpeed).job = this.attackSpeed;
    attributes.get(RoleAttributeEnum.CastSpeed).job = this.castSpeed;
    attributes.get(RoleAttributeEnum.MoveSpeed).job = this.moveSpeed;
  }

  /** 血量 */
  get hp(): number {
    return this.table.attribute.hp;
  }

  /** 魔法 */
  get mp(): number {
    return this.table.attribute.mp;
  }

  /** 物理攻击 */
  get attack(): number {
    return this.table.attribute.attack;
  }

  /** 魔法攻击 */
  get magicAttack(): number {
    return this.table.attribute.magicAttack;
  }

  /** 物理防御 */
  get defense(): number {
    return this.table.attribute.defense;
  }

  /** 魔法防御 */
  get magicDefense(): number {
    return this.table.attribute.magicDefense;
  }

  /** 攻击速度 */
  get attackSpeed(): number {
    return this.table.attribute.attackSpeed;
  }

  /** 释放速度 */
  get castSpeed(): number {
    return this.table.attribute.castSpeed;
  }

  /** 释放速度 */
  get moveSpeed(): number {
    return this.table.attribute.moveSpeed;
  }

  /** 预制件路径 */
  get prefabPath(): string {
    return this.table.prefabPath;
  }

  /** 龙骨资源 */
  get roleDragonBones(): RoleDragonBonesList {
    return {
      upperBody: this.table.upperBody,
      lowerBody: this.table.lowerBody,
    };
  }

  vmAdd() {}
  vmRemove() {}
  reset(entity: ecs.Entity): void {}
}
